﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ETL.Common.Logging;
using ETL.DataAccess;
using ETL.Entity;

namespace ETL.Business.Handlers.ProjectNamesHandler
{
    public class SetSelectedProject
    {
        private readonly ProjectUserRepository _projectUserRepository;

        public SetSelectedProject()
        {
            _projectUserRepository = new ProjectUserRepository();
        }
        public SetSelectedProject(ProjectUserRepository projectUserRepository)
        {
            _projectUserRepository = projectUserRepository;
        }

        public virtual int Execute(string userId, int? selectedProjectId, string selectedProjectName)
        {
            int result = 0;
            try
            {
                if(selectedProjectId.HasValue)
                {
                    result = _projectUserRepository.UpdateSelectedProject(userId, selectedProjectId.Value, selectedProjectName);
                }
                
                return result;
            }
            catch (Exception ex)
            {
                LogService.Service.Debug(ex);
                return result;
            }
        }
    }
}
